package com.Endurancer.manager.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class StreamUtils {

    /**
     * 从输入流中读取所有数据并转换为字符串
     *
     * @param inputStream 输入流
     * @param charsetName 字符集名称，例如"utf-8"
     * @return 读取的字符串
     * @throws IOException 如果读取过程中发生错误
     */
    public static String inputStream2String(InputStream inputStream, String charsetName) throws IOException {
        StringBuilder sb = new StringBuilder();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, charsetName))) {
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
        }
        return sb.toString();
    }

    // 你可以在这里添加其他流处理的工具方法
}
